//
//  TENAIManagerViewController.m
//  TintExample
//
//  Created by Kevin Wu on 2/24/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TENAIManagerViewController.h"


@implementation TENAIManagerViewController

#pragma mark - Memory

- (void)dealloc {
    TTRelease(_scrollView);
    
    TTRelease(_userA);
    TTRelease(_userB);
    TTRelease(_userC);
    [super dealloc];
}



#pragma mark - UIViewController

- (void)loadView {
    [super loadView];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.autoresizingMask = TTViewAutoresizingKeepMargin;
    [self.view addSubview:_scrollView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    _userA = [[NSObject alloc] init];
//    _userB = [[NSArray alloc] init];
//    _userC = [[UIView alloc] init];
    
    _userA = [[NSString alloc] initWithFormat:@"ABC"];
    _userB = [[NSString alloc] initWithFormat:@"ABC"];
    _userC = [[NSString alloc] initWithFormat:@"ABC"];
    
    
    [self addButtonWithTitle:@"add A" selector:@selector(addUserA:) type:1];
    [self addButtonWithTitle:@"add B" selector:@selector(addUserB:) type:1];
    [self addButtonWithTitle:@"add C" selector:@selector(addUserC:) type:1];
    [self addButtonWithTitle:@"add nil" selector:@selector(addNilUser:) type:1];
    [self addButtonWithTitle:@"add all" selector:@selector(addAllUsers:) type:1];
    
    [self addButtonWithTitle:@"remove A" selector:@selector(removeUserA:) type:2];
    [self addButtonWithTitle:@"remove B" selector:@selector(removeUserB:) type:2];
    [self addButtonWithTitle:@"remove C" selector:@selector(removeUserC:) type:2];
    [self addButtonWithTitle:@"remove all" selector:@selector(removeAllUsers:) type:2];
    
    [self addButtonWithTitle:@"is A use network?" selector:@selector(isUserAUseNetwork:) type:3];
    [self addButtonWithTitle:@"is B use network?" selector:@selector(isUserBUseNetwork:) type:3];
    [self addButtonWithTitle:@"is C use network?" selector:@selector(isUserCUseNetwork:) type:3];
}

- (void)addUserA:(id)sender {
    [[TTNAIManager sharedObject] addNetworkUser:_userA];
}
- (void)addUserB:(id)sender {
    [[TTNAIManager sharedObject] addNetworkUser:_userB];
}
- (void)addUserC:(id)sender {
    [[TTNAIManager sharedObject] addNetworkUser:_userC];
}

- (void)removeUserA:(id)sender {
    [[TTNAIManager sharedObject] removeNetworkUser:_userA];
}
- (void)removeUserB:(id)sender {
    [[TTNAIManager sharedObject] removeNetworkUser:_userB];
}
- (void)removeUserC:(id)sender {
    [[TTNAIManager sharedObject] removeNetworkUser:_userC];
}

- (void)addNilUser:(id)sender {
    [[TTNAIManager sharedObject] addNetworkUser:nil];
}
- (void)addAllUsers:(id)sender {
    [[TTNAIManager sharedObject] addNetworkUser:_userA];
    [[TTNAIManager sharedObject] addNetworkUser:_userB];
    [[TTNAIManager sharedObject] addNetworkUser:_userC];
}
- (void)removeAllUsers:(id)sender {
    [[TTNAIManager sharedObject] removeNetworkUser:_userA];
    [[TTNAIManager sharedObject] removeNetworkUser:_userB];
    [[TTNAIManager sharedObject] removeNetworkUser:_userC];
}

- (void)isUserAUseNetwork:(id)sender {
    if ([[TTNAIManager sharedObject] isNetworkUser:_userA]) {
        NSLog(@"_usrA is network user");
    } else {
        NSLog(@"_usrA isn't network user");
    }
}
- (void)isUserBUseNetwork:(id)sender {
    if ([[TTNAIManager sharedObject] isNetworkUser:_userB]) {
        NSLog(@"_usrB is network user");
    } else {
        NSLog(@"_usrB isn't network user");
    }
}
- (void)isUserCUseNetwork:(id)sender {
    if ([[TTNAIManager sharedObject] isNetworkUser:_userC]) {
        NSLog(@"_usrC is network user");
    } else {
        NSLog(@"_usrC isn't network user");
    }
}

@end
